package com.rockcent.mall.controller;

import com.rockcent.common.common.JsonResult;
import com.rockcent.common.common.RestDoing;
import com.rockcent.common.controller.BaseController;
import com.rockcent.mall.Routes;
import com.rockcent.mall.lib.domain.Bank;
import com.rockcent.mall.lib.repository.BankRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by DK on 16/12/9.
 */
@RestController
public class BankController extends BaseController{

    private final Logger log = LoggerFactory.getLogger(BankController.class);

    @Autowired
    private BankRepository bankRepository;

    /**
     * @api {get} /mall/bank/list 银行列表
     * @apiGroup mall_bank
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain    请求域名
     *
     * @apiSuccess {String} code 银行编码
     * @apiSuccess {String} name 银行名称
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":"1",
     *     "desc":"成功",
     *     "data":{
     *         "dateCreated":"2016-06-13 18:28:41",
     *         "lastUpdated":"2016-11-11 19:08:18",
     *         "code":"ICBC",
     *         "name":"招商"
     *     }
     * }
     */
    @RequestMapping(value = Routes.MALL_BANK_LIST, method = RequestMethod.GET)
    public JsonResult bankList(HttpServletRequest request) {
        RestDoing doing = jsonResult -> {
            List<Bank> bankList = bankRepository.findAll();
            jsonResult.data = bankList;
        };
        return doing.go(request, log);
    }
}
